package STUDENT.TRANDAODAIVI.QUESTION;

//TH1(3 Class): Duck,QuackBehavior, FlyBehavior.
//TH2(3 Class): Duck2,QuackBehavior2,FlyBehavior2.

//Mo ta chung: 
//  Duck va Duck2 deu co class DuckCha de cho cac class Duck khac ke thua:

// +Phuong thuc chung cua Duck la Swim
// +Phuong thuc Display se Override sau khi extends
// +Phuong thuc performFly va performQuack se duoc sap xep sao cho de dang quan ly va nang cap theo
//FlyBehavior va Quackbehavior. Ly do cua viec nay la moi con Duck co dac diem rieng, neu khong dung cach nay
//se bi duplicated code.

//Tuy nhien TH1 su dung interface cho QuackBehavior va FlyBehavior
//			TH2 su dung class     cho QuackBehavior2 va FlyBehavior2

//Em muon hoi la truong hop nao la toi uu nhat va tai sao a ?

class DuckCha {
	FlyBehavior flyBehavior;
	QuackBehavior quackBehavior;
	
	public void swim(){
		System.out.println("Swimming");
	}; 
	public void display(){};
	public void performFly(){
		flyBehavior.fly();
	};
	public void performQuack(){
		quackBehavior.quack();
	};
	
}

class DecoyDuck extends DuckCha {
	public DecoyDuck(){
		flyBehavior=new FlyNoWay();
		quackBehavior=new MuteQuack();
	}
	
	public void display(){
		System.out.println("This is a DecoyDuck");
	}
}
class NormalDuck extends DuckCha {
	public NormalDuck(){
		flyBehavior=new FlyWithWings();
		quackBehavior=new Quack();
	}
	
	public void display(){
		System.out.println("This is a MallardDuck");
	}
}class RubberDuck extends DuckCha {
	public RubberDuck(){
		flyBehavior=new FlyNoWay();
		quackBehavior=new Squeak();
	}
	
	public void display(){
		System.out.println("This is a MallardDuck");
	}
}
public class Duck{
	public static void main(String[] args) {
		NormalDuck aduck=new NormalDuck();
		aduck.display();
		System.out.println("Duck Function: ");
		aduck.swim();
		aduck.performFly();
		aduck.performQuack();
		RubberDuck bduck=new RubberDuck();
		bduck.display();
		System.out.println("Duck Function: ");
		bduck.swim();
		bduck.performFly();
		bduck.performQuack();
		DecoyDuck cduck=new DecoyDuck();
		cduck.display();
		System.out.println("Duck Function: ");
		cduck.swim();
		cduck.performFly();
		cduck.performQuack();
		
	}
}